
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>3、断路器hystrix的使用 · 王坤个人博客</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="wk">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-donate/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-prism/prism-duotone-dark.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="4、断路器hystrix的隔离策略.html" />
    
    
    <link rel="prev" href="2、服务调用.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    
    
        
        <li>
            <a href="https://my.oschina.net/kunBlog" target="_blank" class="custom-link">我的博客地址</a>
        </li>
    
    

    
    <li class="divider"></li>
    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../cassandra/">
            
                <a href="../cassandra/">
            
                    
                    Cassandra
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../cassandra/1、cassandra的安装.html">
            
                <a href="../cassandra/1、cassandra的安装.html">
            
                    
                    1、cassandra的安装
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../docker/">
            
                <a href="../docker/">
            
                    
                    Docker
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../docker/1、docker与虚拟机的不同.html">
            
                <a href="../docker/1、docker与虚拟机的不同.html">
            
                    
                    1、docker与虚拟机的不同
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../docker/2、镜像、容器、仓库.html">
            
                <a href="../docker/2、镜像、容器、仓库.html">
            
                    
                    2、镜像、容器、仓库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../docker/3、在centos中安装.html">
            
                <a href="../docker/3、在centos中安装.html">
            
                    
                    3、在centos中安装
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../docker/4、配置私有镜像仓库.html">
            
                <a href="../docker/4、配置私有镜像仓库.html">
            
                    
                    4、配置私有镜像仓库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../docker/5、docker的命令.html">
            
                <a href="../docker/5、docker的命令.html">
            
                    
                    5、docker的命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="../docker/6、镜像的原理.html">
            
                <a href="../docker/6、镜像的原理.html">
            
                    
                    6、镜像的原理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.7" data-path="../docker/7、创建一个镜像.html">
            
                <a href="../docker/7、创建一个镜像.html">
            
                    
                    7、创建一个镜像
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.8" data-path="../docker/8、容器数据卷-持久化文件或目录.html">
            
                <a href="../docker/8、容器数据卷-持久化文件或目录.html">
            
                    
                    8、容器数据卷(持久化文件或目录)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.9" data-path="../docker/9、dockerfile.html">
            
                <a href="../docker/9、dockerfile.html">
            
                    
                    9、dockerfile
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.10" data-path="../docker/10、创建自己的tomcat镜像.html">
            
                <a href="../docker/10、创建自己的tomcat镜像.html">
            
                    
                    10、创建自己的tomcat镜像
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.11" data-path="../docker/11、使用docker安装mysql和redis.html">
            
                <a href="../docker/11、使用docker安装mysql和redis.html">
            
                    
                    11、使用docker安装mysql和redis
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.12" data-path="../docker/12、把本地镜像发布到阿里云.html">
            
                <a href="../docker/12、把本地镜像发布到阿里云.html">
            
                    
                    12、把本地镜像发布到阿里云
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../golang/">
            
                <a href="../golang/">
            
                    
                    Golang
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" >
            
                <span>
            
                    
                    Examples
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1.1" data-path="../golang/examples/1、生成随机数.html">
            
                <a href="../golang/examples/1、生成随机数.html">
            
                    
                    1、生成随机数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.1.2" data-path="../golang/examples/2、数组冒泡排序.html">
            
                <a href="../golang/examples/2、数组冒泡排序.html">
            
                    
                    2、数组冒泡排序
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.1.3" data-path="../golang/examples/3、二分查找.html">
            
                <a href="../golang/examples/3、二分查找.html">
            
                    
                    3、二分查找
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.1.4" data-path="../golang/examples/4、工厂模式.html">
            
                <a href="../golang/examples/4、工厂模式.html">
            
                    
                    4、工厂模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.1.5" data-path="../golang/examples/5、对切片排序.html">
            
                <a href="../golang/examples/5、对切片排序.html">
            
                    
                    5、对切片排序
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4.2" >
            
                <span>
            
                    
                    go的命令行
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.2.1" data-path="../golang/go的命令行/1、go的get命令.html">
            
                <a href="../golang/go的命令行/1、go的get命令.html">
            
                    
                    1、go get 命令
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4.3" >
            
                <span>
            
                    
                    json序列化
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.3.1" data-path="../golang/json序列化/1、json序列化.html">
            
                <a href="../golang/json序列化/1、json序列化.html">
            
                    
                    1、json序列化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3.2" data-path="../golang/json序列化/2、json反序列化.html">
            
                <a href="../golang/json序列化/2、json反序列化.html">
            
                    
                    2、json反序列化
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4.4" >
            
                <span>
            
                    
                    包管理工具
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.4.1" data-path="../golang/包管理工具/dep包管理工具.html">
            
                <a href="../golang/包管理工具/dep包管理工具.html">
            
                    
                    dep包管理工具
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4.5" >
            
                <span>
            
                    
                    协程和管道
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.5.1" data-path="../golang/协程和管道/1、goroutine基础.html">
            
                <a href="../golang/协程和管道/1、goroutine基础.html">
            
                    
                    1、goroutine基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5.2" data-path="../golang/协程和管道/2、goroutine的调度模型.html">
            
                <a href="../golang/协程和管道/2、goroutine的调度模型.html">
            
                    
                    2、goroutine的调度模型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5.3" data-path="../golang/协程和管道/3、全局锁和管道.html">
            
                <a href="../golang/协程和管道/3、全局锁和管道.html">
            
                    
                    3、全局锁和管道
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5.4" data-path="../golang/协程和管道/4、管道.html">
            
                <a href="../golang/协程和管道/4、管道.html">
            
                    
                    4、管道
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5.5" data-path="../golang/协程和管道/5、管道的注意点.html">
            
                <a href="../golang/协程和管道/5、管道的注意点.html">
            
                    
                    5、管道的注意点
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4.6" >
            
                <span>
            
                    
                    单元测试
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.6.1" data-path="../golang/单元测试/1、单元测试入门.html">
            
                <a href="../golang/单元测试/1、单元测试入门.html">
            
                    
                    1、单元测试入门
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4.7" >
            
                <span>
            
                    
                    反射
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.7.1" data-path="../golang/反射/1、反射.html">
            
                <a href="../golang/反射/1、反射.html">
            
                    
                    1、反射
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7.2" data-path="../golang/反射/2、反射的使用细节.html">
            
                <a href="../golang/反射/2、反射的使用细节.html">
            
                    
                    2、反射的使用细节
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4.8" >
            
                <span>
            
                    
                    常量
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.8.1" data-path="../golang/常量/1、常量.html">
            
                <a href="../golang/常量/1、常量.html">
            
                    
                    1、常量
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4.9" >
            
                <span>
            
                    
                    文件操作
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.9.1" data-path="../golang/文件操作/1、读取文件.html">
            
                <a href="../golang/文件操作/1、读取文件.html">
            
                    
                    1、读取文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.9.2" data-path="../golang/文件操作/2、写文件.html">
            
                <a href="../golang/文件操作/2、写文件.html">
            
                    
                    2、写文件
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4.10" >
            
                <span>
            
                    
                    网络编程
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.10.1" data-path="../golang/网络编程/1、网络编程基础.html">
            
                <a href="../golang/网络编程/1、网络编程基础.html">
            
                    
                    1、网络编程基础
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4.11" >
            
                <span>
            
                    
                    面向对象
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.11.1" data-path="../golang/面向对象/1、go使用struct实现OOP.html">
            
                <a href="../golang/面向对象/1、go使用struct实现OOP.html">
            
                    
                    1、go使用struct实现OOP
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.11.2" data-path="../golang/面向对象/2、方法.html">
            
                <a href="../golang/面向对象/2、方法.html">
            
                    
                    2、方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.11.3" data-path="../golang/面向对象/3、封装.html">
            
                <a href="../golang/面向对象/3、封装.html">
            
                    
                    3、封装
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.11.4" data-path="../golang/面向对象/4、继承.html">
            
                <a href="../golang/面向对象/4、继承.html">
            
                    
                    4、继承
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.11.5" data-path="../golang/面向对象/5、接口.html">
            
                <a href="../golang/面向对象/5、接口.html">
            
                    
                    5、接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.11.6" data-path="../golang/面向对象/6、多肽.html">
            
                <a href="../golang/面向对象/6、多肽.html">
            
                    
                    6、多肽
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.11.7" data-path="../golang/面向对象/7、类型断言.html">
            
                <a href="../golang/面向对象/7、类型断言.html">
            
                    
                    7、类型断言
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4.12" data-path="../golang/1、windows下安装golang环境.html">
            
                <a href="../golang/1、windows下安装golang环境.html">
            
                    
                    1、windows下安装golang环境
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.13" data-path="../golang/2、webStorm安装go语言插件.html">
            
                <a href="../golang/2、webStorm安装go语言插件.html">
            
                    
                    2、webStorm安装go语言插件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.14" data-path="../golang/3、go的一些语法风格.html">
            
                <a href="../golang/3、go的一些语法风格.html">
            
                    
                    3、go的一些语法风格
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.15" data-path="../golang/4、go语法-变量.html">
            
                <a href="../golang/4、go语法-变量.html">
            
                    
                    4、go语法-变量
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.16" data-path="../golang/5、go语法--数据类型.html">
            
                <a href="../golang/5、go语法--数据类型.html">
            
                    
                    5、go语法--数据类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.17" data-path="../golang/6、go的整数类型.html">
            
                <a href="../golang/6、go的整数类型.html">
            
                    
                    6、go的整数类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.18" data-path="../golang/7、go的浮点类型.html">
            
                <a href="../golang/7、go的浮点类型.html">
            
                    
                    7、go的浮点类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.19" data-path="../golang/8、go的字符类型.html">
            
                <a href="../golang/8、go的字符类型.html">
            
                    
                    8、go的字符类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.20" data-path="../golang/9、go的bool类型.html">
            
                <a href="../golang/9、go的bool类型.html">
            
                    
                    9、go的bool类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.21" data-path="../golang/10、go的string类型.html">
            
                <a href="../golang/10、go的string类型.html">
            
                    
                    10、go的string类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.22" data-path="../golang/11、基本数据类型相互转换.html">
            
                <a href="../golang/11、基本数据类型相互转换.html">
            
                    
                    11、基本数据类型相互转换
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.23" data-path="../golang/12、基本数据类型和string的转换.html">
            
                <a href="../golang/12、基本数据类型和string的转换.html">
            
                    
                    12、基本数据类型和string的转换
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.24" data-path="../golang/13、go的指针.html">
            
                <a href="../golang/13、go的指针.html">
            
                    
                    13、go的指针
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.25" data-path="../golang/14、go的标识符.html">
            
                <a href="../golang/14、go的标识符.html">
            
                    
                    14、go的标识符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.26" data-path="../golang/15、go的关键字.html">
            
                <a href="../golang/15、go的关键字.html">
            
                    
                    15、go的关键字
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.27" data-path="../golang/16、go的运算符-算术运算.html">
            
                <a href="../golang/16、go的运算符-算术运算.html">
            
                    
                    16、go的运算符-算术运算
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.28" data-path="../golang/17、比较、赋值、逻辑运算符.html">
            
                <a href="../golang/17、比较、赋值、逻辑运算符.html">
            
                    
                    17、比较、赋值、逻辑运算符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.29" data-path="../golang/18、运算符的优先级.html">
            
                <a href="../golang/18、运算符的优先级.html">
            
                    
                    18、运算符的优先级
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.30" data-path="../golang/19、其他运算符.html">
            
                <a href="../golang/19、其他运算符.html">
            
                    
                    19、其他运算符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.31" data-path="../golang/20、go获取键盘输入.html">
            
                <a href="../golang/20、go获取键盘输入.html">
            
                    
                    20、go获取键盘输入
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.32" data-path="../golang/21、进制、位运算.html">
            
                <a href="../golang/21、进制、位运算.html">
            
                    
                    21、进制、位运算
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.33" data-path="../golang/22、if和switch语句.html">
            
                <a href="../golang/22、if和switch语句.html">
            
                    
                    22、if和switch语句
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.34" data-path="../golang/23、for循环.html">
            
                <a href="../golang/23、for循环.html">
            
                    
                    23、for循环
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.35" data-path="../golang/24、goto语句.html">
            
                <a href="../golang/24、goto语句.html">
            
                    
                    24、goto语句
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.36" data-path="../golang/25、函数1.html">
            
                <a href="../golang/25、函数1.html">
            
                    
                    25、函数1
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.37" data-path="../golang/26、包-package.html">
            
                <a href="../golang/26、包-package.html">
            
                    
                    26、包-package
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.38" data-path="../golang/27、init函数.html">
            
                <a href="../golang/27、init函数.html">
            
                    
                    27、init函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.39" data-path="../golang/28、匿名函数.html">
            
                <a href="../golang/28、匿名函数.html">
            
                    
                    28、匿名函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.40" data-path="../golang/29、闭包.html">
            
                <a href="../golang/29、闭包.html">
            
                    
                    29、闭包
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.41" data-path="../golang/30、defer.html">
            
                <a href="../golang/30、defer.html">
            
                    
                    30、defer
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.42" data-path="../golang/31、值传递和引用传递.html">
            
                <a href="../golang/31、值传递和引用传递.html">
            
                    
                    31、值传递和引用传递
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.43" data-path="../golang/32、常用字符串函数.html">
            
                <a href="../golang/32、常用字符串函数.html">
            
                    
                    32、常用字符串函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.44" data-path="../golang/33、时间和日期函数.html">
            
                <a href="../golang/33、时间和日期函数.html">
            
                    
                    33、时间和日期函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.45" data-path="../golang/34、go语言的内置函数.html">
            
                <a href="../golang/34、go语言的内置函数.html">
            
                    
                    34、go语言的内置函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.46" data-path="../golang/35、go语言的错误处理.html">
            
                <a href="../golang/35、go语言的错误处理.html">
            
                    
                    35、go语言的错误处理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.47" data-path="../golang/36、数组.html">
            
                <a href="../golang/36、数组.html">
            
                    
                    36、数组
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.48" data-path="../golang/37、切片slice.html">
            
                <a href="../golang/37、切片slice.html">
            
                    
                    37、切片slice
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.49" data-path="../golang/38、string和slice.html">
            
                <a href="../golang/38、string和slice.html">
            
                    
                    38、string 和 slice
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.50" data-path="../golang/39、二维数组.html">
            
                <a href="../golang/39、二维数组.html">
            
                    
                    39、二维数组
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.51" data-path="../golang/40、map的用法.html">
            
                <a href="../golang/40、map的用法.html">
            
                    
                    40、map的用法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.52" data-path="../golang/41、获取命令行参数.html">
            
                <a href="../golang/41、获取命令行参数.html">
            
                    
                    41、获取命令行参数
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../Istio/">
            
                <a href="../Istio/">
            
                    
                    Istio
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../redis/">
            
                <a href="../redis/">
            
                    
                    Redis
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" >
            
                <span>
            
                    
                    golang连接redis
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1.1" data-path="../redis/golang连接redis/1、go语言连接使用redis.html">
            
                <a href="../redis/golang连接redis/1、go语言连接使用redis.html">
            
                    
                    1、go语言连接使用redis
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.1.2" data-path="../redis/golang连接redis/2、redis连接池.html">
            
                <a href="../redis/golang连接redis/2、redis连接池.html">
            
                    
                    2、redis连接池
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6.2" >
            
                <span>
            
                    
                    protected-mode设置
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.2.1" data-path="../redis/protected-mode设置/1、设置保护模式.html">
            
                <a href="../redis/protected-mode设置/1、设置保护模式.html">
            
                    
                    1、设置保护模式
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../redis/1、redis的安装.html">
            
                <a href="../redis/1、redis的安装.html">
            
                    
                    1、redis的安装
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="../redis/2、redis数据库的命令操作.html">
            
                <a href="../redis/2、redis数据库的命令操作.html">
            
                    
                    2、redis数据库的命令操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="../redis/3、string类型的操作.html">
            
                <a href="../redis/3、string类型的操作.html">
            
                    
                    3、string类型的操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.6" data-path="../redis/4、hash类型的操作.html">
            
                <a href="../redis/4、hash类型的操作.html">
            
                    
                    4、hash类型的操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.7" data-path="../redis/5、list类型的操作.html">
            
                <a href="../redis/5、list类型的操作.html">
            
                    
                    5、list类型的操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.8" data-path="../redis/6、Set类型的操作.html">
            
                <a href="../redis/6、Set类型的操作.html">
            
                    
                    6、Set类型的操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.9" data-path="../redis/7、docker安装redis.html">
            
                <a href="../redis/7、docker安装redis.html">
            
                    
                    7、docker安装redis
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.10" data-path="../redis/8、redis集群搭建.html">
            
                <a href="../redis/8、redis集群搭建.html">
            
                    
                    8、redis集群搭建
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.11" data-path="../redis/9、zset类型的操作.html">
            
                <a href="../redis/9、zset类型的操作.html">
            
                    
                    9、zset类型的操作
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" >
            
                <span>
            
                    
                    数据结构和算法
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../数据结构和算法/1、稀疏数组.html">
            
                <a href="../数据结构和算法/1、稀疏数组.html">
            
                    
                    1、稀疏数组
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../数据结构和算法/2、队列.html">
            
                <a href="../数据结构和算法/2、队列.html">
            
                    
                    2、队列
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="../数据结构和算法/3、单向链表.html">
            
                <a href="../数据结构和算法/3、单向链表.html">
            
                    
                    3、单向链表
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.4" data-path="../数据结构和算法/4、双向链表.html">
            
                <a href="../数据结构和算法/4、双向链表.html">
            
                    
                    4、双向链表
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.5" data-path="../数据结构和算法/5、单向环形链表.html">
            
                <a href="../数据结构和算法/5、单向环形链表.html">
            
                    
                    5、单向环形链表
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.6" data-path="../数据结构和算法/6、约瑟夫问题.html">
            
                <a href="../数据结构和算法/6、约瑟夫问题.html">
            
                    
                    6、约瑟夫问题
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.7" data-path="../数据结构和算法/7、选择排序.html">
            
                <a href="../数据结构和算法/7、选择排序.html">
            
                    
                    7、选择排序
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.8" data-path="../数据结构和算法/8、插入排序.html">
            
                <a href="../数据结构和算法/8、插入排序.html">
            
                    
                    8、插入排序
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.9" data-path="../数据结构和算法/9、快速排序法.html">
            
                <a href="../数据结构和算法/9、快速排序法.html">
            
                    
                    9、快速排序法
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="./">
            
                <a href="./">
            
                    
                    springCloud
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="consul/">
            
                <a href="consul/">
            
                    
                    consul
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1.1" data-path="consul/1、springcloud服务注册到consul.html">
            
                <a href="consul/1、springcloud服务注册到consul.html">
            
                    
                    1、springcloud服务注册到consul
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.1.2" data-path="consul/2、springcloud消费consul中注册的服务.html">
            
                <a href="consul/2、springcloud消费consul中注册的服务.html">
            
                    
                    2、springcloud消费consul中注册的服务
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.1.3" data-path="consul/3、springcloud使用consul做配置中心.html">
            
                <a href="consul/3、springcloud使用consul做配置中心.html">
            
                    
                    3、springcloud使用consul做配置中心
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="springBoot/">
            
                <a href="springBoot/">
            
                    
                    springBoot
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.2.1" >
            
                <span>
            
                    
                    一些问题解决方式
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.2.1.1" data-path="springBoot/一些问题解决方式/1、StreamingResponseBody问题.html">
            
                <a href="springBoot/一些问题解决方式/1、StreamingResponseBody问题.html">
            
                    
                    1、StreamingResponseBody问题
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8.2.2" data-path="springBoot/1、新建springboot工程.html">
            
                <a href="springBoot/1、新建springboot工程.html">
            
                    
                    1、新建springboot工程
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="1、Eureka服务注册中心.html">
            
                <a href="1、Eureka服务注册中心.html">
            
                    
                    1、Eureka服务注册中心
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.4" data-path="2、服务调用.html">
            
                <a href="2、服务调用.html">
            
                    
                    2、服务调用
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.8.5" data-path="3、断路器hystrix的使用.html">
            
                <a href="3、断路器hystrix的使用.html">
            
                    
                    3、断路器hystrix的使用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.6" data-path="4、断路器hystrix的隔离策略.html">
            
                <a href="4、断路器hystrix的隔离策略.html">
            
                    
                    4、断路器hystrix的隔离策略
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.7" data-path="5、hystrix的Dashboard和Turbine.html">
            
                <a href="5、hystrix的Dashboard和Turbine.html">
            
                    
                    5、hystrix的Dashboard和Turbine
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../vpn/">
            
                <a href="../vpn/">
            
                    
                    Vpn
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" data-path="../vpn/1、ss服务器的安装.html">
            
                <a href="../vpn/1、ss服务器的安装.html">
            
                    
                    1、ss服务器的安装
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.2" data-path="../vpn/2、SS客户端.html">
            
                <a href="../vpn/2、SS客户端.html">
            
                    
                    2、SS客户端
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.10" >
            
                <span>
            
                    
                    gitbook的使用
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.10.1" data-path="../gitbook的使用/1、gitbook的使用.html">
            
                <a href="../gitbook的使用/1、gitbook的使用.html">
            
                    
                    1、gitbook 的使用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.2" data-path="../gitbook的使用/2、gitbook命令.html">
            
                <a href="../gitbook的使用/2、gitbook命令.html">
            
                    
                    2、gitbook命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.3" data-path="../gitbook的使用/3、gitbook连续大括号的解决方式.html">
            
                <a href="../gitbook的使用/3、gitbook连续大括号的解决方式.html">
            
                    
                    3、gitbook连续大括号的解决方式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.4" data-path="../gitbook的使用/4、gitbook插件.html">
            
                <a href="../gitbook的使用/4、gitbook插件.html">
            
                    
                    4、gitbook插件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.5" data-path="../gitbook的使用/5、去掉-本书由gitbook发布.html">
            
                <a href="../gitbook的使用/5、去掉-本书由gitbook发布.html">
            
                    
                    5、去掉-本书由gitbook发布
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.11" >
            
                <span>
            
                    
                    markdown学习
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.11.1" data-path="../markdown学习/1、markdown的学习.html">
            
                <a href="../markdown学习/1、markdown的学习.html">
            
                    
                    1、markdown的学习
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="../keycloak/">
            
                <a href="../keycloak/">
            
                    
                    keycloak
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.12.1" data-path="../keycloak/1、keycloak的简单使用.html">
            
                <a href="../keycloak/1、keycloak的简单使用.html">
            
                    
                    1、keycloak的简单使用
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.13" >
            
                <span>
            
                    
                    分布式事务
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.13.1" data-path="../分布式事务/1、事务的介绍.html">
            
                <a href="../分布式事务/1、事务的介绍.html">
            
                    
                    1、事务的介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.2" data-path="../分布式事务/2、分布式事务的理论.html">
            
                <a href="../分布式事务/2、分布式事务的理论.html">
            
                    
                    2、分布式事务的理论
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >3、断路器hystrix的使用</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-navicon"></i><ul><ul><li><span class="title-icon "></span><a href="#&#x4E00;&#x3001;&#x65AD;&#x8DEF;&#x5668;&#x7684;&#x4F5C;&#x7528;&#x3002;"><b>1.1. </b>&#x4E00;&#x3001;&#x65AD;&#x8DEF;&#x5668;&#x7684;&#x4F5C;&#x7528;&#x3002;</a></li><li><span class="title-icon "></span><a href="#&#x4E8C;&#x3001;&#x4F7F;&#x7528;hystrix&#x3002;"><b>1.2. </b>&#x4E8C;&#x3001;&#x4F7F;&#x7528;hystrix&#x3002;</a></li><ul><li><span class="title-icon "></span><a href="#21&#x3001;user-provider-&#x670D;&#x52A1;&#x7AEF;&#x4EE3;&#x7801;&#x3002;"><b>1.2.1. </b>2.1&#x3001;user-provider &#x670D;&#x52A1;&#x7AEF;&#x4EE3;&#x7801;&#x3002;</a></li><li><span class="title-icon "></span><a href="#22&#x3001;&#x5BA2;&#x6237;&#x7AEF;&#x3002;"><b>1.2.2. </b>2.2&#x3001;&#x5BA2;&#x6237;&#x7AEF;&#x3002;</a></li></ul><li><span class="title-icon "></span><a href="#&#x5B9E;&#x9645;&#x4F7F;&#x7528;&#x3002;"><b>1.3. </b>&#x5B9E;&#x9645;&#x4F7F;&#x7528;&#x3002;</a></li><li><span class="title-icon "></span><a href="#&#x6587;&#x6863;&#x3002;"><b>1.4. </b>&#x6587;&#x6863;&#x3002;</a></li><li><span class="title-icon "></span><a href="#hystrix&#x505C;&#x6B62;&#x5F00;&#x53D1;&#x4E86;&#x3002;"><b>1.5. </b>Hystrix&#x505C;&#x6B62;&#x5F00;&#x53D1;&#x4E86;&#x3002;</a></li></ul></ul></div><a href="#" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a><h2 id="&#x4E00;&#x3001;&#x65AD;&#x8DEF;&#x5668;&#x7684;&#x4F5C;&#x7528;&#x3002;"><a name="&#x4E00;&#x3001;&#x65AD;&#x8DEF;&#x5668;&#x7684;&#x4F5C;&#x7528;&#x3002;" class="anchor-navigation-ex-anchor" href="#&#x4E00;&#x3001;&#x65AD;&#x8DEF;&#x5668;&#x7684;&#x4F5C;&#x7528;&#x3002;"><i class="fa fa-link" aria-hidden="true"></i></a>1.1. &#x4E00;&#x3001;&#x65AD;&#x8DEF;&#x5668;&#x7684;&#x4F5C;&#x7528;&#x3002;</h2>
<p>&#x65AD;&#x8DEF;&#x5668;&#x7684;&#x4F5C;&#x7528;&#x662F;&#x5F53;&#x67D0;&#x4E2A;&#x670D;&#x52A1;&#x7684;&#x67D0;&#x4E2A;&#x5B9E;&#x4F8B;&#x5F02;&#x5E38;&#x4E86;&#xFF08;&#x670D;&#x52A1;&#x5B9E;&#x4F8B;&#x6302;&#x4E86;&#xFF0C;&#x53CD;&#x5E94;&#x6162;&#x7B49;&#xFF09;&#xFF0C;&#x8C03;&#x7528;&#x8FD9;&#x4E2A;&#x670D;&#x52A1;&#x7684;&#x5BA2;&#x6237;&#x7AEF;&#x5C31;&#x4F1A;&#x6267;&#x884C;&#x540E;&#x5907;&#x7684;&#x65AD;&#x8DEF;&#x5668;&#x65B9;&#x6CD5;&#x3002;
&#x907F;&#x514D;&#x6574;&#x4E2A;&#x670D;&#x52A1;&#x4E0D;&#x53EF;&#x7528;&#x3002;  </p>
<blockquote>
<p>&#x4F8B;&#x5982;&#xFF1A;&#x5728;&#x53CC;11&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x63A8;&#x8350;&#x670D;&#x52A1;&#x53CD;&#x5E94;&#x5F88;&#x6162;&#xFF0C;&#x5BFC;&#x81F4;&#x67E5;&#x8BE2;&#x63A8;&#x8350;&#x5F88;&#x6162;&#x3002;&#x56E0;&#x4E3A;&#x63A8;&#x8350;&#x670D;&#x52A1;&#x4E0D;&#x662F;&#x6700;&#x6838;&#x5FC3;&#x7684;&#x670D;&#x52A1;&#xFF0C;&#x8C03;&#x7528;&#x63A8;&#x8350;&#x670D;&#x52A1;&#x7684;client&#x7AEF;&#x53EF;&#x4EE5;&#x8FD4;&#x56DE;&#x9884;&#x7559;&#x7684;&#x63A8;&#x8350;&#x5546;&#x54C1;&#x3002;&#x4ECE;&#x800C;&#x907F;&#x514D;&#x6574;&#x4E2A;&#x670D;&#x52A1;&#x5361;&#x5728;&#x63A8;&#x8350;&#x670D;&#x52A1;&#x4E0A;&#x3002;  </p>
</blockquote>
<p>client&#x7AEF;&#x4F7F;&#x7528;&#x65AD;&#x8DEF;&#x5668;<code>hystrix</code>&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x670D;&#x52A1;&#x63D0;&#x4F9B;&#x65B9;&#x5B9E;&#x4F8B;&#x5982;&#x679C;&#x4E00;&#x4E2A;&#x7279;&#x522B;&#x6162;&#xFF08;10&#x79D2;&#x8FD4;&#x56DE;&#xFF09;&#xFF0C;&#x4E00;&#x4E2A;&#x7279;&#x522B;&#x5FEB;&#xFF08;&#x7ACB;&#x5373;&#x8FD4;&#x56DE;&#xFF09;&#x3002;&#x5982;&#x679C;<code>hystrix</code>&#x8C03;&#x7528;&#x7AEF;&#x8BBE;&#x7F6E;&#x8D85;&#x65F6;&#x65F6;&#x95F4;&#x662F;3&#x79D2;&#x3002; &#x5982;&#x679C;&#x843D;&#x5230;&#x7279;&#x522B;&#x6162;&#x7684;&#x670D;&#x52A1;&#x5B9E;&#x4F8B;&#x4E5F;&#x4F1A;&#x51FA;&#x73B0;&#x65AD;&#x8DEF;&#x3002;&#x4F1A;&#x6267;&#x884C;&#x65AD;&#x8DEF;&#x7684;&#x903B;&#x8F91;&#x3002;</p>
<h2 id="&#x4E8C;&#x3001;&#x4F7F;&#x7528;hystrix&#x3002;"><a name="&#x4E8C;&#x3001;&#x4F7F;&#x7528;hystrix&#x3002;" class="anchor-navigation-ex-anchor" href="#&#x4E8C;&#x3001;&#x4F7F;&#x7528;hystrix&#x3002;"><i class="fa fa-link" aria-hidden="true"></i></a>1.2. &#x4E8C;&#x3001;&#x4F7F;&#x7528;hystrix&#x3002;</h2>
<h3 id="21&#x3001;user-provider-&#x670D;&#x52A1;&#x7AEF;&#x4EE3;&#x7801;&#x3002;"><a name="21&#x3001;user-provider-&#x670D;&#x52A1;&#x7AEF;&#x4EE3;&#x7801;&#x3002;" class="anchor-navigation-ex-anchor" href="#21&#x3001;user-provider-&#x670D;&#x52A1;&#x7AEF;&#x4EE3;&#x7801;&#x3002;"><i class="fa fa-link" aria-hidden="true"></i></a>1.2.1. 2.1&#x3001;user-provider &#x670D;&#x52A1;&#x7AEF;&#x4EE3;&#x7801;&#x3002;</h3>
<p>&#x670D;&#x52A1;&#x7AEF;&#x5C31;&#x53EA;&#x6709;&#x4E00;&#x4E2A;<code>/test/add</code> &#x63A5;&#x53E3;&#x3002;&#x628A;&#x670D;&#x52A1;&#x6CE8;&#x518C;&#x5230;&#x6CE8;&#x518C;&#x4E2D;&#x5FC3;&#x5373;&#x53EF;&#x3002;</p>
<pre class="language-"><code class="lang-java"><span class="token annotation punctuation">@RestController</span>
<span class="token annotation punctuation">@RequestMapping</span><span class="token punctuation">(</span><span class="token string">&quot;/test&quot;</span><span class="token punctuation">)</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">TestController</span> <span class="token punctuation">{</span>

    <span class="token annotation punctuation">@GetMapping</span><span class="token punctuation">(</span><span class="token string">&quot;/add&quot;</span><span class="token punctuation">)</span>
    <span class="token keyword">public</span> <span class="token keyword">int</span> <span class="token function">add</span><span class="token punctuation">(</span><span class="token keyword">int</span> a<span class="token punctuation">,</span><span class="token keyword">int</span> b<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">try</span> <span class="token punctuation">{</span>
            <span class="token class-name">TimeUnit</span><span class="token punctuation">.</span>SECONDS<span class="token punctuation">.</span><span class="token function">sleep</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;add &#x6267;&#x884C;&#x5B8C;&#x6210; &#x3002;&#x3002;&#x3002;&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span> <span class="token keyword">catch</span> <span class="token punctuation">(</span><span class="token class-name">InterruptedException</span> e<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            e<span class="token punctuation">.</span><span class="token function">printStackTrace</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token keyword">return</span> a <span class="token operator">+</span> b<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

<span class="token punctuation">}</span>
</code></pre>
<h3 id="22&#x3001;&#x5BA2;&#x6237;&#x7AEF;&#x3002;"><a name="22&#x3001;&#x5BA2;&#x6237;&#x7AEF;&#x3002;" class="anchor-navigation-ex-anchor" href="#22&#x3001;&#x5BA2;&#x6237;&#x7AEF;&#x3002;"><i class="fa fa-link" aria-hidden="true"></i></a>1.2.2. 2.2&#x3001;&#x5BA2;&#x6237;&#x7AEF;&#x3002;</h3>
<h4 id="221&#x3001;&#x4F9D;&#x8D56;&#x914D;&#x7F6E;&#x3002;"><a name="221&#x3001;&#x4F9D;&#x8D56;&#x914D;&#x7F6E;&#x3002;" class="anchor-navigation-ex-anchor" href="#221&#x3001;&#x4F9D;&#x8D56;&#x914D;&#x7F6E;&#x3002;"><i class="fa fa-link" aria-hidden="true"></i></a>2.2.1&#x3001;&#x4F9D;&#x8D56;&#x914D;&#x7F6E;&#x3002;</h4>
<pre class="language-"><code class="lang-xml"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">&gt;</span></span>org.springframework.boot<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">&gt;</span></span>spring-boot-starter-web<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">&gt;</span></span>org.springframework.cloud<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">&gt;</span></span>spring-cloud-starter-netflix-eureka-client<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">&gt;</span></span>org.springframework.cloud<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">&gt;</span></span>spring-cloud-starter-openfeign<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">&gt;</span></span>org.springframework.cloud<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">&gt;</span></span>spring-cloud-starter-netflix-hystrix<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">&gt;</span></span>
</code></pre>
<p>&#x4F7F;&#x7528;&#x4E86;<code>openfeign</code>&#x548C;<code>hystrix</code>&#x3002;</p>
<h4 id="222&#x3001;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x3002;"><a name="222&#x3001;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x3002;" class="anchor-navigation-ex-anchor" href="#222&#x3001;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x3002;"><i class="fa fa-link" aria-hidden="true"></i></a>2.2.2&#x3001;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x3002;</h4>
<p><code>application.yml</code>&#x914D;&#x7F6E;&#x5982;&#x4E0B;&#xFF1A;  </p>
<pre class="language-"><code class="lang-yaml"><span class="token key atrule">server</span><span class="token punctuation">:</span>
  <span class="token key atrule">port</span><span class="token punctuation">:</span> <span class="token number">9002</span>
<span class="token key atrule">spring</span><span class="token punctuation">:</span>
  <span class="token key atrule">application</span><span class="token punctuation">:</span>
    <span class="token key atrule">name</span><span class="token punctuation">:</span> user<span class="token punctuation">-</span>consumer<span class="token punctuation">-</span>hystrix
  <span class="token key atrule">cloud</span><span class="token punctuation">:</span>
    <span class="token key atrule">loadbalancer</span><span class="token punctuation">:</span>
      <span class="token key atrule">retry</span><span class="token punctuation">:</span>
        <span class="token comment"># &#x9ED8;&#x8BA4;&#x5C31;&#x662F;false</span>
        <span class="token key atrule">enabled</span><span class="token punctuation">:</span> <span class="token boolean important">false</span>
<span class="token comment">#  datasource:</span>
<span class="token comment">#    driverClassName: com.mysql.jdbc.Driver</span>
<span class="token comment">#    url: jdbc:mysql://localhost:3306/user-consumer?serverTimezone=GMT%2b8</span>
<span class="token comment">#    username: root</span>
<span class="token comment">#    password: 123456</span>
<span class="token key atrule">eureka</span><span class="token punctuation">:</span>
  <span class="token key atrule">client</span><span class="token punctuation">:</span>
    <span class="token key atrule">serviceUrl</span><span class="token punctuation">:</span>
      <span class="token comment"># &#x6CE8;&#x518C;&#x4E2D;&#x5FC3;&#x7684;&#x5730;&#x5740;</span>
      <span class="token key atrule">defaultZone</span><span class="token punctuation">:</span> http<span class="token punctuation">:</span>//localhost<span class="token punctuation">:</span>9999/eureka/
  <span class="token key atrule">instance</span><span class="token punctuation">:</span>
    <span class="token key atrule">preferIpAddress</span><span class="token punctuation">:</span> <span class="token boolean important">true</span>
    <span class="token key atrule">instanceId</span><span class="token punctuation">:</span> $<span class="token punctuation">{</span>spring.cloud.client.ip<span class="token punctuation">-</span>address<span class="token punctuation">}</span><span class="token punctuation">:</span>$<span class="token punctuation">{</span>server.port<span class="token punctuation">}</span>
<span class="token comment">#user-provider:</span>
<span class="token comment">#  ribbon:</span>
<span class="token comment">#    NFLoadBalancerRuleClassName: com.netflix.loadbalancer.WeightedResponseTimeRule</span>


<span class="token key atrule">feign</span><span class="token punctuation">:</span>
<span class="token comment">#  client:</span>
<span class="token comment">#    config:</span>
<span class="token comment">#      default:</span>
 <span class="token comment">#&#x5728;&#x4F7F;&#x7528;hystrix&#x65F6;&#xFF0C;&#x914D;&#x7F6E;&#x8FD9;&#x4E2A;&#x4E0D;&#x80FD;&#x6539;&#x53D8;HTTP&#x8FDE;&#x63A5;&#x7684;readTimeout&#x3002;</span>
<span class="token comment">#        readTimeout: 1000</span>
  <span class="token key atrule">hystrix</span><span class="token punctuation">:</span>
    <span class="token comment"># &#x5F00;&#x542F; hystrix</span>
    <span class="token key atrule">enabled</span><span class="token punctuation">:</span> <span class="token boolean important">true</span>
<span class="token key atrule">ribbon</span><span class="token punctuation">:</span>
  <span class="token comment"># &#x5BF9;&#x5F53;&#x524D;&#x5B9E;&#x4F8B;&#x7684;&#x6700;&#x5927;&#x91CD;&#x8BD5;&#x6B21;&#x6570; (&#x5305;&#x542B;&#x7B2C;&#x4E00;&#x6B21;&#x8BF7;&#x6C42;)</span>
  <span class="token key atrule">MaxAutoRetries</span><span class="token punctuation">:</span> <span class="token number">0</span>
  <span class="token key atrule">OkToRetryOnAllOperations</span><span class="token punctuation">:</span> <span class="token boolean important">false</span>
<span class="token comment"># &#x5207;&#x6362;&#x5B9E;&#x4F8B;&#x7684;&#x6700;&#x5927;&#x91CD;&#x8BD5;&#x6B21;&#x6570;(&#x5982;&#x679C;&#x91CD;&#x8BD5;&#x5931;&#x8D25;&#x5C31;&#x5207;&#x6362;&#x4E0B;&#x4E00;&#x4E2A;&#x670D;&#x52A1;&#x5B9E;&#x4F8B;&#xFF09;&#xFF0C;&#x4E0B;&#x4E00;&#x4E2A;&#x670D;&#x52A1;&#x5B9E;&#x4F8B;&#x7684;&#x91CD;&#x8BD5;&#x6B21;&#x6570;(&#x5305;&#x542B;&#x7B2C;&#x4E00;&#x6B21;&#x8BF7;&#x6C42;)</span>
  <span class="token key atrule">MaxAutoRetriesNextServer</span><span class="token punctuation">:</span> <span class="token number">0</span>
<span class="token comment"># &#x53EA;&#x6709;&#x4E0B;&#x9762;&#x7684;2&#x4E2A;&#x914D;&#x7F6E;&#x624D;&#x53EF;&#x4EE5;&#x6539;&#x53D8; http&#x7684;ReadTimeout&#x3001;ConnectTimeout</span>
  <span class="token key atrule">ReadTimeout</span><span class="token punctuation">:</span> <span class="token number">20000</span>
  <span class="token key atrule">ConnectTimeout</span><span class="token punctuation">:</span> <span class="token number">5000</span>
<span class="token key atrule">hystrix</span><span class="token punctuation">:</span>
  <span class="token key atrule">command</span><span class="token punctuation">:</span>
    <span class="token key atrule">default</span><span class="token punctuation">:</span>
      <span class="token key atrule">execution</span><span class="token punctuation">:</span>
        <span class="token key atrule">timeout</span><span class="token punctuation">:</span>
          <span class="token comment"># &#x9ED8;&#x8BA4;&#x5F00;&#x542F;&#x8D85;&#x65F6;&#x673A;&#x5236;</span>
          <span class="token key atrule">enabled</span><span class="token punctuation">:</span> <span class="token boolean important">true</span>
        <span class="token key atrule">isolation</span><span class="token punctuation">:</span>
          <span class="token key atrule">thread</span><span class="token punctuation">:</span>
            <span class="token comment"># timeoutInMilliseconds&#x5FC5;&#x987B;&#x5927;&#x4E8E;ribbon.ReadTimeout&#x3002;</span>
            <span class="token comment">#&#x5982;&#x679C;ribbon&#x91CD;&#x8BD5;&#x591A;&#x6B21;&#xFF0C;&#x90A3;timeoutInMilliseconds&#x5FC5;&#x987B;&#x5927;&#x4E8E;ribbon.ReadTimeout&#x4E58;&#x4EE5;&#x91CD;&#x8BD5;&#x6B21;&#x6570;</span>
            <span class="token key atrule">timeoutInMilliseconds</span><span class="token punctuation">:</span> <span class="token number">60000</span>
</code></pre>
<ol>
<li>&#x9700;&#x8981;&#x8BBE;&#x7F6E;<code>feign.hystrix.enabled=true</code>&#x8BA9;Feign&#x652F;&#x6301;hystrix&#x3002;<code>hystrix</code> &#x4F7F;&#x7528; <code>feign</code>&#x6765;&#x53D1;&#x9001;&#x8BF7;&#x6C42;&#xFF0C;<code>feign</code>&#x7528;<code>ribbon</code>&#x505A;&#x8D1F;&#x8F7D;&#x5747;&#x8861;&#x3002;</li>
<li><p>&#x9700;&#x8981;&#x7279;&#x522B;&#x6CE8;&#x610F;<code>ribbon</code>&#x7684;&#x51E0;&#x4E2A;&#x53C2;&#x6570;&#xFF1A;<a href="https://cloud.spring.io/spring-cloud-static/Greenwich.SR3/single/spring-cloud.html#_configuration" target="_blank">&#x5B98;&#x65B9;&#x6587;&#x6863;</a>     </p>
<blockquote>
<ul>
<li><code>MaxAutoRetries</code> &#x91CD;&#x8BD5;&#x5F53;&#x524D;&#x5B9E;&#x4F8B;&#x7684;&#x6B21;&#x6570;&#x3002;(&#x5305;&#x542B;&#x7B2C;&#x4E00;&#x6B21;&#x8BF7;&#x6C42;)  </li>
<li><code>MaxAutoRetriesNextServer</code> &#x91CD;&#x8BD5;&#x4E0B;&#x4E00;&#x4E2A;&#x670D;&#x52A1;&#x5668;&#x7684;&#x6B21;&#x6570;&#x3002;&#xFF08;&#x5305;&#x542B;&#x7B2C;&#x4E00;&#x4E2A;&#x5B9E;&#x4F8B;&#xFF09;  </li>
<li><code>OkToRetryOnAllOperations</code> &#x5BF9;&#x6240;&#x6709;&#x64CD;&#x4F5C;&#x8BF7;&#x6C42;&#x90FD;&#x8FDB;&#x884C;&#x91CD;&#x8BD5;&#x3002;<br>&#x5F53;&#x8BBF;&#x95EE;&#x5230;&#x6545;&#x969C;&#x8BF7;&#x6C42;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x5B83;&#x4F1A;&#x518D;&#x91CD;&#x8BD5;&#x8BBF;&#x95EE;&#x5F53;&#x524D;&#x5B9E;&#x4F8B;&#xFF08;&#x6B21;&#x6570;&#x7531;MaxAutoRetries&#x914D;&#x7F6E;&#xFF09;&#xFF0C;&#x5982;&#x679C;&#x4E0D;&#x884C;&#xFF0C;&#x5C31;&#x6362;&#x4E00;&#x4E2A;&#x5B9E;&#x4F8B;&#x8FDB;&#x884C;&#x8BBF;&#x95EE;&#xFF0C;&#x5982;&#x679C;&#x8FD8;&#x662F;&#x4E0D;&#x884C;&#xFF0C;&#x518D;&#x6362;&#x4E00;&#x6B21;&#x5B9E;&#x4F8B;&#x8BBF;&#x95EE;&#xFF08;&#x66F4;&#x6362;&#x5B9E;&#x4F8B;&#x6B21;&#x6570;&#x7531;MaxAutoRetriesNextServer&#x914D;&#x7F6E;&#xFF09;&#xFF0C;&#x5982;&#x679C;&#x4F9D;&#x7136;&#x4E0D;&#x884C;&#xFF0C;&#x8FD4;&#x56DE;&#x5931;&#x8D25;&#x4FE1;&#x606F;&#x3002;<br><code>MaxAutoRetries</code>&#x3001;<code>MaxAutoRetriesNextServer</code> &#x5FC5;&#x987B;&#x8BBE;&#x7F6E;&#x4E3A;0&#xFF0C;&#x5426;&#x5219;&#x5728;&#x505A;&#x589E;&#x52A0;&#x3001;&#x4FEE;&#x6539;&#x64CD;&#x4F5C;&#x65F6;&#x5FC5;&#x987B;&#x662F;&#x5E42;&#x7B49;&#x7684;&#x3002;  </li>
</ul>
</blockquote>
</li>
<li><p>&#x9700;&#x8981;&#x6CE8;&#x610F;&#x51E0;&#x4E2A;&#x8D85;&#x65F6;&#x65F6;&#x95F4;&#x3002;</p>
<blockquote>
<ul>
<li><code>ribbon.ReadTimeout</code>&#x3001;<code>ribbon.ConnectTimeout</code> &#x8FD9;2&#x4E2A;&#x662F;&#x8BBE;&#x7F6E;HTTP&#x7684;&#x8D85;&#x65F6;&#x65F6;&#x95F4;&#x3002;&#x4F8B;&#x5982;&#xFF1A;&#x670D;&#x52A1;&#x63D0;&#x4F9B;&#x65B9;&#x7684;&#x67D0;&#x4E2A;http&#x8BF7;&#x6C42;&#x9700;&#x8981;10&#x79D2;&#x624D;&#x8FD4;&#x56DE;&#xFF0C;&#x90A3;<code>ribbon.ReadTimeout</code>&#x5FC5;&#x987B;&#x8BBE;&#x7F6E;&#x8D85;&#x8FC7;10&#x79D2;&#x3002;
&#x5426;&#x5219;&#x4F1A;&#x8D85;&#x65F6;&#x5931;&#x8D25;&#x3002;&#x5982;&#x4E0B;&#x56FE;&#xFF1A;<br><img src="images/3107c1d2c2b9fb1e441dff4b3665d60.png" alt="">  </li>
<li><code>hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds</code> &#x8FD9;&#x4E2A;&#x8BBE;&#x7F6E;hystrix&#x7684;&#x8D85;&#x65F6;&#x65F6;&#x95F4;&#x3002;Hystrix&#x5C01;&#x88C5;&#x4E86;Ribbon&#x5BA2;&#x6237;&#x7AEF;&#x3002;
timeoutInMilliseconds&#x5FC5;&#x987B;&#x5927;&#x4E8E;ribbon.ReadTimeout&#x3002;&#x5982;&#x679C;ribbon&#x91CD;&#x8BD5;&#x591A;&#x6B21;&#xFF0C;&#x90A3;timeoutInMilliseconds&#x5FC5;&#x987B;&#x5927;&#x4E8E;ribbon.ReadTimeout&#x4E58;&#x4EE5;&#x91CD;&#x8BD5;&#x6B21;&#x6570;&#x3002;hystrix&#x8D85;&#x65F6;&#x65F6;&#x95F4;&#x7684;&#x8BA1;&#x7B97;&#xFF1A; <code>(1 + MaxAutoRetries + MaxAutoRetriesNextServer) * ReadTimeout</code>&#x3002;
&#x8BE6;&#x7EC6;&#x67E5;&#x770B;<a href="https://cloud.spring.io/spring-cloud-static/Greenwich.SR3/single/spring-cloud.html#_hystrix_timeouts_and_ribbon_clients" target="_blank">&#x5B98;&#x65B9;&#x6587;&#x6863;</a>  </li>
<li><code>feign.client.config.default.readTimeout</code> &#x8FD9;&#x4E2A;&#x8D85;&#x65F6;&#x65F6;&#x95F4;&#x5728;hystrix&#x8FD9;&#x91CC;&#x597D;&#x50CF;&#x5931;&#x6548;&#x4E86;&#x3002;&#x8BBE;&#x7F6E;&#x5927;&#x5C0F;&#x90FD;&#x65E0;&#x5173;&#x7D27;&#x8981;&#x3002;<br><a href="https://cloud.spring.io/spring-cloud-static/Greenwich.SR3/single/spring-cloud.html#_retrying_failed_requests" target="_blank">springcloud&#x5B98;&#x65B9;&#x8D85;&#x65F6;&#x91CD;&#x8BD5;&#x7684;&#x6587;&#x6863;</a><br>ribbon&#x5B98;&#x65B9;&#x91CD;&#x8BD5;&#x53C2;&#x6570;&#x8BBE;&#x7F6E;&#xFF1A;<br><a href="https://github.com/Netflix/ribbon/wiki/Getting-Started#the-properties-file-sample-clientproperties" target="_blank">https://github.com/Netflix/ribbon/wiki/Getting-Started#the-properties-file-sample-clientproperties</a>  </li>
</ul>
</blockquote>
</li>
</ol>
<h4 id="223&#x3001;&#x542F;&#x7528;&#x65AD;&#x8DEF;&#x5668;&#x3002;"><a name="223&#x3001;&#x542F;&#x7528;&#x65AD;&#x8DEF;&#x5668;&#x3002;" class="anchor-navigation-ex-anchor" href="#223&#x3001;&#x542F;&#x7528;&#x65AD;&#x8DEF;&#x5668;&#x3002;"><i class="fa fa-link" aria-hidden="true"></i></a>2.2.3&#x3001;&#x542F;&#x7528;&#x65AD;&#x8DEF;&#x5668;&#x3002;</h4>
<p>&#x4F7F;&#x7528;<code>@EnableCircuitBreaker</code> &#x542F;&#x7528;&#x65AD;&#x8DEF;&#x5668;&#xFF0C;&#x4F7F;&#x7528;<code>@EnableFeignClients</code>&#x542F;&#x7528;<code>Feign</code>&#x3002;  </p>
<pre class="language-"><code class="lang-java"><span class="token annotation punctuation">@EnableCircuitBreaker</span>
<span class="token annotation punctuation">@EnableFeignClients</span>
<span class="token annotation punctuation">@SpringBootApplication</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">UserConsumerHystrixApplication</span> <span class="token punctuation">{</span>

    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token class-name">SpringApplication</span><span class="token punctuation">.</span><span class="token function">run</span><span class="token punctuation">(</span><span class="token class-name">UserConsumerHystrixApplication</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">,</span> args<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

<span class="token punctuation">}</span>
</code></pre>
<h4 id="224&#x3001;&#x8C03;&#x7528;&#x670D;&#x52A1;&#x3002;"><a name="224&#x3001;&#x8C03;&#x7528;&#x670D;&#x52A1;&#x3002;" class="anchor-navigation-ex-anchor" href="#224&#x3001;&#x8C03;&#x7528;&#x670D;&#x52A1;&#x3002;"><i class="fa fa-link" aria-hidden="true"></i></a>2.2.4&#x3001;&#x8C03;&#x7528;&#x670D;&#x52A1;&#x3002;</h4>
<pre class="language-"><code class="lang-java"><span class="token comment">/**
 *&#x8C03;&#x7528;user-provider &#x670D;&#x52A1;&#x3002;
 */</span>
<span class="token annotation punctuation">@FeignClient</span><span class="token punctuation">(</span>name <span class="token operator">=</span> <span class="token string">&quot;user-provider&quot;</span><span class="token punctuation">,</span>fallback <span class="token operator">=</span> <span class="token class-name">UserProviderClientFallback</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">)</span>
<span class="token keyword">public</span> <span class="token keyword">interface</span> <span class="token class-name">UserProviderClient</span> <span class="token punctuation">{</span>

<span class="token comment">//    @HystrixCommand(fallbackMethod = &quot;defaultAdd&quot;)</span>
    <span class="token comment">// &#x8BF7;&#x6C42;/test/add &#x63A5;&#x53E3;</span>
    <span class="token annotation punctuation">@GetMapping</span><span class="token punctuation">(</span><span class="token string">&quot;/test/add&quot;</span><span class="token punctuation">)</span>
    <span class="token keyword">int</span> <span class="token function">add</span><span class="token punctuation">(</span><span class="token annotation punctuation">@RequestParam</span><span class="token punctuation">(</span>name <span class="token operator">=</span> <span class="token string">&quot;a&quot;</span><span class="token punctuation">)</span> <span class="token keyword">int</span> a<span class="token punctuation">,</span> <span class="token annotation punctuation">@RequestParam</span><span class="token punctuation">(</span>name <span class="token operator">=</span> <span class="token string">&quot;b&quot;</span><span class="token punctuation">)</span> <span class="token keyword">int</span> b<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
<pre class="language-"><code class="lang-java"><span class="token comment">/**
 *UserProviderClient&#x7684;&#x65AD;&#x8DEF;&#x5668;&#xFF0C;&#x540E;&#x5907;&#x6267;&#x884C;&#x903B;&#x8F91;&#x3002;&#xFF08;&#x670D;&#x52A1;&#x964D;&#x7EA7;&#xFF09;
 */</span>
<span class="token annotation punctuation">@Component</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">UserProviderClientFallback</span> <span class="token keyword">implements</span> <span class="token class-name">UserProviderClient</span><span class="token punctuation">{</span>
    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token keyword">int</span> <span class="token function">add</span><span class="token punctuation">(</span><span class="token keyword">int</span> a<span class="token punctuation">,</span> <span class="token keyword">int</span> b<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;UserProviderClient add &#x51FA;&#x95EE;&#x9898;&#x4E86;&#x3002;&#x3002;&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">return</span> a <span class="token operator">+</span> b <span class="token operator">+</span> <span class="token number">10000</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x4F7F;&#x7528;<code>@FeignClient</code>&#x6CE8;&#x89E3;&#x58F0;&#x660E;&#x4E86;&#x8981;&#x8C03;&#x7528;<code>name = &quot;user-provider&quot;</code>&#x7684;&#x670D;&#x52A1;&#xFF0C;
&#x5E76;&#x4E14;&#x8C03;&#x7528;&#x670D;&#x52A1;<code>user-provider</code>&#x51FA;&#x95EE;&#x9898;&#x4E4B;&#x540E;&#x6267;&#x884C;&#x7684;&#x540E;&#x5907;&#x903B;&#x8F91;&#x662F;<code>UserProviderClientFallback.class</code>&#x91CC;&#x9762;&#x5BF9;&#x5E94;&#x7684;&#x65B9;&#x6CD5;&#x3002;    </p>
<h4 id="225&#x3001;&#x6D4B;&#x8BD5;&#x4EE3;&#x7801;&#x3002;"><a name="225&#x3001;&#x6D4B;&#x8BD5;&#x4EE3;&#x7801;&#x3002;" class="anchor-navigation-ex-anchor" href="#225&#x3001;&#x6D4B;&#x8BD5;&#x4EE3;&#x7801;&#x3002;"><i class="fa fa-link" aria-hidden="true"></i></a>2.2.5&#x3001;&#x6D4B;&#x8BD5;&#x4EE3;&#x7801;&#x3002;</h4>
<pre class="language-"><code class="lang-java"><span class="token annotation punctuation">@RestController</span>
<span class="token annotation punctuation">@RequestMapping</span><span class="token punctuation">(</span><span class="token string">&quot;/test&quot;</span><span class="token punctuation">)</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">TestHystrixController</span> <span class="token punctuation">{</span>

    <span class="token annotation punctuation">@Autowired</span>
    <span class="token keyword">private</span> <span class="token class-name">UserProviderClient</span> userProviderClient<span class="token punctuation">;</span>

    <span class="token annotation punctuation">@GetMapping</span><span class="token punctuation">(</span><span class="token string">&quot;/hystrix/callAdd&quot;</span><span class="token punctuation">)</span>
    <span class="token keyword">public</span> <span class="token keyword">int</span> <span class="token function">callAdd</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> userProviderClient<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">,</span><span class="token number">8</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x8BBF;&#x95EE; <code>http://localhost:9002/test/hystrix/callAdd</code> &#x53EF;&#x4EE5;&#x770B;&#x5230;&#x8FD4;&#x56DE;&#x4E86;<code>10011</code>&#x3002;&#x8BC1;&#x660E;&#x6267;&#x884C;&#x4E86;&#x540E;&#x5907;&#x903B;&#x8F91;&#x3002;
&#x5B9E;&#x9645;&#x4E0A;&#x5C31;&#x662F;<code>user-consumer-hystrix</code>&#x670D;&#x52A1;&#x8C03;&#x7528;<code>user-provider</code>&#x670D;&#x52A1;&#xFF0C;<code>user-provider</code>&#x8981;10&#x79D2;&#x624D;&#x8FD4;&#x56DE;&#xFF0C;<code>hystrix</code>&#x8BBE;&#x7F6E;&#x4E86;3&#x79D2;&#x8D85;&#x65F6;&#x3002;&#x6240;&#x4EE5;&#x6267;&#x884C;&#x4E86;&#x540E;&#x5907;&#x903B;&#x8F91;&#x3002;
&#x6CE8;&#x610F;&#x8BF7;&#x6C42;&#x5DF2;&#x7ECF;&#x5230;&#x8FBE;&#x4E86;<code>user-provider</code>&#xFF0C;<code>user-provider</code>&#x8FD8;&#x662F;&#x4F1A;&#x6267;&#x884C;&#x5B8C;&#x81EA;&#x5DF1;&#x7684;add&#x65B9;&#x6CD5;&#x3002;  </p>
<h2 id="&#x5B9E;&#x9645;&#x4F7F;&#x7528;&#x3002;"><a name="&#x5B9E;&#x9645;&#x4F7F;&#x7528;&#x3002;" class="anchor-navigation-ex-anchor" href="#&#x5B9E;&#x9645;&#x4F7F;&#x7528;&#x3002;"><i class="fa fa-link" aria-hidden="true"></i></a>1.3. &#x5B9E;&#x9645;&#x4F7F;&#x7528;&#x3002;</h2>
<p>&#x5728;fallback&#x51FD;&#x6570;&#x4E2D;&#xFF0C;&#x53EF;&#x4EE5;&#x5F02;&#x6B65;&#x53D1;&#x9001;&#x77ED;&#x4FE1;&#x901A;&#x77E5;&#x5F00;&#x53D1;&#x4EBA;&#x5458;&#x3002;&#x5982;&#x679C;&#x662F;&#x4E0B;&#x5355;&#x5931;&#x8D25;&#xFF0C;&#x53EF;&#x4EE5;&#x77ED;&#x4FE1;&#x901A;&#x77E5;&#x5BA2;&#x6237;&#x4E0B;&#x5355;&#x5931;&#x8D25;&#x3002;  </p>
<h2 id="&#x6587;&#x6863;&#x3002;"><a name="&#x6587;&#x6863;&#x3002;" class="anchor-navigation-ex-anchor" href="#&#x6587;&#x6863;&#x3002;"><i class="fa fa-link" aria-hidden="true"></i></a>1.4. &#x6587;&#x6863;&#x3002;</h2>
<p><a href="https://cloud.spring.io/spring-cloud-static/Greenwich.SR3/single/spring-cloud.html#spring-cloud-feign-hystrix" target="_blank">springcloud-hystrix&#x5B98;&#x65B9;&#x6587;&#x6863;</a><br>&#x5B98;&#x65B9;&#x6587;&#x6863;&#xFF1A;<a href="https://cloud.spring.io/spring-cloud-static/Greenwich.SR3/single/spring-cloud.html#spring-cloud-feign-hystrix-fallback" target="_blank">&#x83B7;&#x53D6;fallback&#x539F;&#x56E0;</a><br>&#x5B98;&#x65B9;&#x6587;&#x6863;&#xFF1A;<a href="https://cloud.spring.io/spring-cloud-static/Greenwich.SR3/single/spring-cloud.html#_feign_and_primary" target="_blank">&#x591A;&#x4E2A;bean&#x6CE8;&#x5165;&#x62A5;&#x9519;&#x7684;&#x95EE;&#x9898;</a>  </p>
<h2 id="hystrix&#x505C;&#x6B62;&#x5F00;&#x53D1;&#x4E86;&#x3002;"><a name="hystrix&#x505C;&#x6B62;&#x5F00;&#x53D1;&#x4E86;&#x3002;" class="anchor-navigation-ex-anchor" href="#hystrix&#x505C;&#x6B62;&#x5F00;&#x53D1;&#x4E86;&#x3002;"><i class="fa fa-link" aria-hidden="true"></i></a>1.5. Hystrix&#x505C;&#x6B62;&#x5F00;&#x53D1;&#x4E86;&#x3002;</h2>
<p>&#x5728;<a href="https://github.com/Netflix/Hystrix" target="_blank">Hystrix&#x5B98;&#x7F51;</a>&#x4E0A;&#x8BF4;&#x4E86;Hystrix&#x5DF2;&#x7ECF;&#x505C;&#x6B62;&#x5F00;&#x53D1;&#x4E86;&#xFF0C;
&#x76EE;&#x524D;&#x662F;&#x5728;&#x7EF4;&#x62A4;&#x4E2D;&#xFF0C;&#x8FD8;&#x80FD;&#x4F7F;&#x7528;&#x3002;&#x66FF;&#x4EE3;&#x4EA7;&#x54C1;&#x6709;&#x4EE5;&#x4E0B;&#x51E0;&#x4E2A;&#xFF1A;<a href="http://www.itmuch.com/spring-cloud-sum/hystrix-no-longer/" target="_blank">&#x53C2;&#x8003;&#x535A;&#x5BA2;</a>    </p>
<ul>
<li><a href="https://github.com/resilience4j/resilience4j" target="_blank">Resilience4J</a>&#xFF0C;&#x5B98;&#x65B9;&#x63A8;&#x8350;&#x3002;   </li>
<li><a href="https://github.com/alibaba/Sentinel" target="_blank">Alibaba Sentinel</a>  </li>
</ul>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="2、服务调用.html" class="navigation navigation-prev " aria-label="Previous page: 2、服务调用">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="4、断路器hystrix的隔离策略.html" class="navigation navigation-next " aria-label="Next page: 4、断路器hystrix的隔离策略">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"3、断路器hystrix的使用","level":"1.8.5","depth":2,"next":{"title":"4、断路器hystrix的隔离策略","level":"1.8.6","depth":2,"path":"springCloud/4、断路器hystrix的隔离策略.md","ref":"springCloud/4、断路器hystrix的隔离策略.md","articles":[]},"previous":{"title":"2、服务调用","level":"1.8.4","depth":2,"path":"springCloud/2、服务调用.md","ref":"springCloud/2、服务调用.md","articles":[]},"dir":"ltr"},"config":{"plugins":["donate","copy-code-button","expandable-chapters","prism","prism-themes","-highlight","anchor-navigation-ex","-sharing","sharing-plus"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"prism":{"css":["prism-themes/themes/prism-duotone-dark.css"]},"search":{},"sharing-plus":{"qq":false,"all":["facebook","google","twitter","instapaper","linkedin","pocket","stumbleupon"],"douban":false,"facebook":true,"weibo":false,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":true,"messenger":false,"line":false,"vk":false,"pocket":true,"google":false,"viber":false,"stumbleupon":false,"qzone":false,"linkedin":false},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"donate":{"alipay":"/gitbook的使用/Donate/alipay.jpg","alipayText":"支付宝打赏","button":"捐赠","title":"如果您觉得有用，请我喝杯水。","wechat":"/gitbook的使用/Donate/wechat.png","wechatText":"微信打赏"},"fontsettings":{"theme":"white","family":"sans","size":2},"anchor-navigation-ex":{"associatedWithSummary":true,"float":{"floatIcon":"fa fa-navicon","level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"mode":"float","multipleH1":true,"pageTop":{"level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"printLog":false,"showGoTop":true,"showLevel":true},"prism-themes":{},"copy-code-button":{},"sharing":{"qq":true,"all":["weibo","douban","google","line","hatenaBookmark","instapaper","viber","vk","whatsapp","stumbleupon","messenger"],"douban":false,"facebook":true,"weibo":true,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":true,"messenger":false,"line":false,"vk":false,"pocket":true,"google":false,"viber":false,"stumbleupon":false,"qzone":true,"linkedin":true},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"expandable-chapters":{}},"theme":"default","author":"wk","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"王坤个人博客","language":"zh-hans","links":{"sidebar":{"我的博客地址":"https://my.oschina.net/kunBlog"}},"gitbook":"3.2.3","description":"王坤个人博客"},"file":{"path":"springCloud/3、断路器hystrix的使用.md","mtime":"2020-02-01T04:13:06.507Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-04-01T11:40:27.319Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-donate/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-copy-code-button/toggle.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing-plus/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

